<template>
  <!-- @click.prevent="handleLink(item)" -->
  <el-breadcrumb class="app-breadcrumb" separator-class="el-icon-arrow-right">
    <transition-group name="breadcrumb">
      <el-breadcrumb-item v-for="(item,index) in levelList" :key="item.path" :class="index==0&&levelList.length>1?'el-bread-one':'el-bread-two'">
        <span v-if="item.redirect==='noRedirect'||index==levelList.length-1" class="breadcrumbClass">{{ item.meta.title }}</span>
        <span v-else class="breadcrumbClass" @click="handleLink(item)">{{ item.meta.title }}</span>
      </el-breadcrumb-item>
    </transition-group>
  </el-breadcrumb>
</template>
<script>
import pathToRegexp from 'path-to-regexp';
import { getToken } from '@/utils/auth.js';
export default {
  data() {
    return {
      levelList: null
    };
  },
  watch: {
    $route() {
      this.getBreadcrumb();
    }
  },
  created() {
    this.getBreadcrumb();
  },
  methods: {
    gotoPath() {
      this.$store.dispatch('tagsView/delAllViews').then(({ visitedViews }) => {
        this.$router.push('/');
      });
    },
    getBreadcrumb() {
      // only show routes with meta.title
      let matched = this.$route.matched.filter(item => item.meta && item.meta.title);
      const first = matched[0];
      if (!this.isDashboard(first)) {
        matched = [{ path: '/', meta: { title: '' }}].concat(matched);
      }
      this.levelList = matched.filter(item => item.meta && item.meta.title);
    },
    isDashboard(route) {
      const name = route && route.name;
      if (!name) {
        return false;
      }
      return name.trim().toLocaleLowerCase() === 'Dashboard'.toLocaleLowerCase();
    },
    pathCompile(path) {
      // To solve this problem https://github.com/PanJiaChen/vue-element-admin/issues/561
      const { params } = this.$route;
      var toPath = pathToRegexp.compile(path);
      return toPath(params);
    },
    handleLink(item) {
      this.$router.push({
        path: getToken('pcUrlName')
      });
      // const { redirect, path } = item;
      // if (redirect) {
      //   this.$router.push(redirect);
      //   return;
      // }
      // this.$router.push(this.pathCompile(path));
    }
  }
};
</script>
<style lang="scss" scoped>
 @import "@/styles/variables.scss";
.back{
    position:absolute;
    top: -2px;
    right: 30px;
}

.el-bread-one >>>.el-breadcrumb__inner a{
  font-size: $zhejiang_auxiliarySize;
  color:$zhejiang_N6;
}
.el-bread-two >>>.el-breadcrumb__inner{
  font-size: $zhejiang_auxiliarySize;
  color:$zhejiang_N8;
}
.breadcrumbClass{
  cursor: pointer;
}
.breadcrumbClass:hover{
  color: $zhejiang_B4;
}
</style>
